<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\AdminController;
use App\Models\Agent;
use App\Models\With as TWith;
use Illuminate\Http\Request;

class With extends AdminController{
    
    public function index(Request $req){
        $psize = 15;
        if($req->method() == 'POST'){
            $list = TWith::orderBy('status')->orderBy('id')->paginate($psize);
            $agents = [];
            foreach ($list as &$v) {
                if (!isset($agents[$v->aid])) {
                    $agents[$v->aid] = Agent::find($v->aid);
                    $agents[$v->aid]->info = json_decode($agents[$v->aid]->alipayinfo,1);
                }
                $v->title = $agents[$v->aid]->mobile;
                $v->info = $agents[$v->aid]->info;
                $v->createtime = date('Y-m-d H:i',$v->createtime);
            }
            wxresp(1, ['rows' => $list->items(), 'total' => $list->total()]);
        }
        return $this->V("index");
    }
    
    public function agree(Request $req){
        $id = $req->input('id', 0);
        $item = TWith::find($id);
        if (!$item) wxresp(0, '提现不存在');
        $item->status = 1;
        $item->save();
        wxresp(1);
    }
}